#!/bin/bash
set -e

run=$1
if [ "$1" == "" ]; then
  echo Error: please set project name, e.g: sh update.sh xxx
  exit 1
fi
workdir=$HOME/vps-monitor
echo Begin Update VPS Monitor: $run
echo Workspace: $workdir
git pull
#复制项目静态文件
cp -r public/** $workdir/$run/public

if [ "$2" != "-s" ]; then
  #编译
  go build -o $workdir/$run/$run
  systemctl restart $run-vm.service
fi
echo Update finish!